Repository navigation
Conversation
Local Claude Code project settings (hooks, permissions) are machine-specific and should not be tracked in the repo.
TranspileExpressionV2's substitute walker named pushdown placeholders via rand.Int63(), so the emitted SQL for a given query was not reproducible across runs. Substitute names only need to be unique within one transpile, so a counter on the per-call Expr struct gives the same guarantee deterministically. This is a hard prerequisite for golden-SQL corpus pinning: two runs of the same (query, step, range) must now emit byte-identical SQL.
Adds the tooling floor for the golden-SQL corpus work: a golangci-lint config scoped to what's actually idiomatic in this codebase (participle grammar struct tags aren't real struct tags, errcheck flags this repo's existing Close()-in-defer style, etc.), -race added to the CI unit-test lane, a Justfile as the single entry point for build/test/ lint/corpus/fuzz recipes, and go-arch-lint wired in report-only mode to baseline current package coupling without gating on it yet.
Introduces reader/internal/goldentest: a TXTAR-based fixture format/loader/writer with a -update regeneration flag, a recording fake implementing the reader's DB session interfaces (IDBRegistry/ ISqlxDB) for driving the real PromQL engine without a live ClickHouse, and a generic parser-pin table-driven test helper. This is the shared harness the three query-head golden corpora build on.
50 fixtures capturing the real PromQL engine's emitted SQL for (query, step, range) tuples, driven end-to-end through the actual engine and a recording DB-session fake so both the pushdown substitution decision and the raw-vs-downsampled table routing are genuinely exercised, not hand-built. Also adds parser AST-shape pins and a native FuzzParse target seeded from representative queries.
64 fixtures pinning the SQL clickhouse_planner.Plan renders for a LogQL query: stream selectors, line/label filters, parsers (json/logfmt/regexp), line_format/label_format, unwrap, range aggregations with by/without grouping, and binary expressions (each side's SQL pinned separately, since the merge itself happens in-process). Also adds parser AST-shape pins and a native FuzzParse target.
39 fixtures pinning both the simple-vs-complex routing decision and the resulting SQL statement(s) for TraceQL queries: attribute/ resource/span selectors, intrinsics, conjunctions, structural operators, pipeline aggregates, and tag/value lookups, with a mix of simple- and complex-routed queries. Also adds parser AST-shape pins and a native FuzzParse target.
525a2df to
57f0df8
Compare
The repo already has a Makefile for e2e/docker workflows; introducing a second build-tool entry point (Justfile) split tooling across two files for no reason. Move build/test-unit/lint/arch-lint/update-golden/ fuzz into Makefile targets (HEAD/DURATION passed as make variables) and drop the Justfile, updating the doc/comment references that pointed at it.
Comments in the fuzz/golden test files and docs/contributing.md's code block alignment still pointed at \`just\` commands after the Justfile was folded into the Makefile.
Resolves the go.mod conflict from upstream's dependency bumps (grpc, go 1.27.0, otel/prometheus deps) against this branch's addition of golang.org/x/tools as a direct dependency: keep the x/tools promotion, take upstream's bumped versions, then `go mod tidy` to reconcile go.sum. Upstream also landed a promql fill-gap fix (include the last step in the grid) that changes generated SQL, so the promql golden corpus is regenerated to match (`make update-golden HEAD=promql`); re-run with -count=2 confirms byte-identical, deterministic output. Full `go test -race ./...` is green post-merge.
golangci-lint refuses to run when its own build's Go toolchain is older than the module's `go` directive. v2.12.2 (this job's pin) was built with go1.26.2, so once master's go.mod bump to 1.27.0 landed here via merge, the lint check started hard-failing with "can't load config" before running a single linter. v2.13.1 is built with go1.27.0 and lints clean locally (0 issues). Also switch the job's Go setup to go-version-file: go.mod so it doesn't drift from the module version again.
|
Hello @tsouza . Thanks. |
|
Hi, thanks for the notes.
The reason for writing it standalone is really to simplify things. I will evaluate those tools to see if any can be used without increasing complexity.
This is part of a larger plan. Indeed this code change alone does not makes sense, but since it's part of a much larger change, I decided to split. See #917 for more context |
Static SQL-text goldens pin today's ClickHouse-specific output shape as a contract, including shapes that may themselves be bugs -- every fix then requires updating both the code and the golden file. Query-behavior pinning now belongs at two other layers instead: decision pins for internal routing/pushdown choices, and response-level goldens for the Loki/ Prometheus/Tempo JSON contracts Grafana actually depends on. Neither is part of this PR; both land in later milestones of the testing epic (metrico#917). What stays: golangci-lint, -race, the Makefile entrypoints, go-arch-lint (report-only), and the rand.Int63() -> per-transpile-counter fix for pushdown-substitute naming, now covered by a direct determinism test (transpile the same expression twice, assert byte-identical output) instead of only being inferred from golden re-runs. What's removed: reader/internal/goldentest (996 lines), the three golden_test.go files, all 153 testdata/golden/*.txtar fixtures, the three corpus-* CI jobs, the update-golden Makefile target and its docs, and .gitattributes (its only content was golden-fixture -merge entries). The parser AST-shape pins and fuzz targets are unaffected and stay -- they're not goldens, and relocate cleanly: parserpin.go moves to its own reader/internal/parserpin package since it has no goldentest dependency. go.mod: golang.org/x/tools reverts from a direct to an indirect dependency now that goldentest.go (its only direct importer) is gone.
… into m1-groundwork-golden-sql-corpus
|
Rescoped this PR after further discussion. Dropped the golden-SQL corpus (153 SQL-text fixtures + the goldentest infra) — a static SQL-text contract pins today's emitted shape, including shapes that may themselves be bugs, so every fix meant two edits (code + golden) instead of one. Query-behavior pinning now lands at two other layers in later milestones instead: decision pins for internal routing/pushdown choices, and response-level goldens for the actual Loki/Prometheus/Tempo JSON contracts. See #917 for the updated milestone order. What's left in this PR: tooling groundwork (golangci-lint, |
Resolves the two real conflicts by hand: master's math/rand/v2 modernization (metrico#954) touched the same rand.Int64() lines this branch's determinism fix replaces with NextSubstituteName() -- kept this branch's fix, which fully supersedes the modernization (no rand import needed once the counter replaces random naming entirely). go.yml auto-merged cleanly, keeping both master's gofmt step and this branch's lint/-race/arch-lint additions.
The pins/seeds landed with the M1 groundwork PR were thin (14-17 parser
pins, 10-14 fuzz seeds per head). Query strings for this expansion are
drawn from two permissively-licensed, cerberus-free upstream sources
already vendored for reference elsewhere:
- PromQL: prometheus/compliance's promql-test-queries.yml (MIT-derived),
template placeholders resolved via its own testVariantArgs table.
- LogQL: grafana/loki's pkg/logql/bench query registry.
- TraceQL: no equivalent clean vendored corpus existed, so only bare
query strings (no fixture names, comments, or expected-result
metadata) were extracted from a local compatibility smoke corpus and
validated independently against this repo's own parser -- one line
mentioning a source project name was excluded outright, consistent
with this project's no-reference-project-mentions policy.
Every candidate was run through this repo's actual Parse() (not assumed
from the source project's behavor) to classify it as a valid-shape pin,
an invalid-syntax pin, or fuzz-only seed material; several negative pins
document real, current parser gaps (unwrap's conversion-function syntax,
empty by()/without() on LRAOrUnwrap, TraceQL's ">"/"<"/"!(" forms) rather
than assuming upstream behavior transfers unchanged.
Also fixes two dangling "golden corpus"/"golden-SQL pinning" comment
references left over from the previous commit's corpus removal.
|
Pushed a follow-up commit enriching the parser AST-shape pins and fuzz seed corpus for all three heads (they were thin: 14-17 pins / 10-14 seeds each). New material is validated against this repo's actual parser (not assumed) and drawn from permissively-licensed upstream sources already vendored for reference elsewhere — prometheus/compliance's query set for PromQL, grafana/loki's pkg/logql/bench registry for LogQL. Several new pins are negative cases documenting real current parser gaps (unwrap conversion-function syntax, empty by()/without() on range aggregations, TraceQL's bare ">"/"<"/"!(" forms) rather than assuming upstream grammar support carries over. |
|
Thanks for the rescope — dropping the SQL-text corpus was the right call, and the PR is much closer to landable. Three more things needed before merging the PR. 1. Remove the parser AST-shape pinsThe four come out cleanly as a unit — the fuzz targets don't import the helper, and nothing else consumes it. The reasoning is the one that retired the SQL corpus, one layer up. These pin the shape of a parsed AST rather than a behaviour, and the coverage already exists at the behaviour level: Two categories are worth calling out specifically:
That last point is the most valuable thing in this PR. Those five are real compatibility bugs, now filed with the upstream grammar citations: #986, #987, #988, #989, #990. Checking them turned up more than the pins covered — 11 of TraceQL's 14 structural operators are unsupported, and all three LogQL 2. Match the Go toolchain to go.modThe arch-lint job pins 3. Confirm the golangci-lint pin still buildsv2.13.1 was pinned when go.mod was on an older Go; worth re-checking against 1.27.1. Keeping: the determinism fix and its direct test — "same input produces the same output" is exactly the kind of invariant that earns a permanent test — plus the three Context for the wider plan is in #917 and the per-milestone comments. Sorry for the delay in replying. Between the work on #972 and the other PRs from @janeblower, we needed to agree on the path forward first so the tests would match the plan rather than the other way round. Let us know whether you'd like to make the three changes, or if you'd rather I do it. |
rita7lopes
left a comment
There was a problem hiding this comment.
Check my comment above
…names (metrico#918) Takes over metrico#925, keeping the scope agreed in its review, and completes the rest of metrico#918. Fix: PromQL pushdown substitutes were named with rand.Int64(), so the same query transpiled to a different residual expression on every run. Each parsed Expr now hands out names from its own counter (Expr.NextSubstituteName). Names stay unique within a query, which is the only scope prom_queryable looks them up in. TestTranspileIsDeterministic transpiles twice and requires a byte-identical residual expression and byte-identical SQL for every substitute. Makefile as the single entry point; CI runs only recipes: - fmt-check, build, test-unit (go test -race ./...), lint, arch-lint, fuzz HEAD=<head> [DURATION=60s] - lint builds golangci-lint v2.14.0 from source and reports only issues new since LINT_NEW_FROM_REV (CI passes the PR base commit). v2.13.x cannot read the export data go1.27.3 writes (format V5 needs golang.org/x/tools >= v0.50.0) - arch-lint runs go-arch-lint v1.19.0 from tools/archlint, which raises golang.org/x/tools to v0.50.0 for the same reason; no go-arch-lint release does yet. Report-only in CI (continue-on-error) Parser fuzzing: - FuzzParse for LogQL, PromQL and TraceQL asserts no panic and that any accepted query round-trips (render, parse, render gives the same text) - "Parser fuzz" workflow, manually dispatched only, uploads crashers - the LogQL crasher it found (dangling and/or in a label filter) is committed as a regression seed Review changes on top of metrico#925: - drop the parser AST-shape pins and the reader/internal/parserpin helper - arch-lint reads the Go version from go.mod instead of pinning 1.26 - bump golangci-lint v2.13.1 -> v2.14.0 (see above) Co-authored-by: Thiago Souza <122435+tsouza@users.noreply.github.com>
…names (#918) (#1059) * chore(ci): M1 tooling groundwork and deterministic PromQL substitute names (#918) Takes over #925, keeping the scope agreed in its review, and completes the rest of #918. Fix: PromQL pushdown substitutes were named with rand.Int64(), so the same query transpiled to a different residual expression on every run. Each parsed Expr now hands out names from its own counter (Expr.NextSubstituteName). Names stay unique within a query, which is the only scope prom_queryable looks them up in. TestTranspileIsDeterministic transpiles twice and requires a byte-identical residual expression and byte-identical SQL for every substitute. Makefile as the single entry point; CI runs only recipes: - fmt-check, build, test-unit (go test -race ./...), lint, arch-lint, fuzz HEAD=<head> [DURATION=60s] - lint builds golangci-lint v2.14.0 from source and reports only issues new since LINT_NEW_FROM_REV (CI passes the PR base commit). v2.13.x cannot read the export data go1.27.3 writes (format V5 needs golang.org/x/tools >= v0.50.0) - arch-lint runs go-arch-lint v1.19.0 from tools/archlint, which raises golang.org/x/tools to v0.50.0 for the same reason; no go-arch-lint release does yet. Report-only in CI (continue-on-error) Parser fuzzing: - FuzzParse for LogQL, PromQL and TraceQL asserts no panic and that any accepted query round-trips (render, parse, render gives the same text) - "Parser fuzz" workflow, manually dispatched only, uploads crashers - the LogQL crasher it found (dangling and/or in a label filter) is committed as a regression seed Review changes on top of #925: - drop the parser AST-shape pins and the reader/internal/parserpin helper - arch-lint reads the Go version from go.mod instead of pinning 1.26 - bump golangci-lint v2.13.1 -> v2.14.0 (see above) Co-authored-by: Thiago Souza <122435+tsouza@users.noreply.github.com> * fix(ci): give lint a base commit on pushes github.event.pull_request.base.sha is empty on a push, so once go.yml runs on pushes to master, `make lint` gets no --new-from-rev and fails on every pre-existing issue. Fall back to github.event.before, the commit before the push, so a push is held to the same "new issues only" rule as a pull request. * chore(ci): drop arch-lint, pin golangci-lint in a tools module Review follow-up for #1059. - Remove go-arch-lint (.go-arch-lint.yml, tools/archlint, the make target and CI job): with every component allowed every dependency and the job set to continue-on-error, it could not report anything. - golangci-lint v2.14.0 is now a tool of a tools/ module, kept current by a Dependabot entry for /tools. make lint runs it from the repo root with go tool -modfile=tools/go.mod, so it lints gigapipe's packages. - .golangci.yml header: CI runs make lint with --new-from-rev; drop the stale golangci-lint-action and corpus references. - Fuzz targets: state that the seed corpus runs under go test ./.... * chore(ci): run golangci-lint@latest instead of a tools module The tools/ module added a second go.mod with a hand-maintained go version that go-version-sync does not update, plus a second Dependabot stream. Run the latest golangci-lint release instead: nothing to bump, and it keeps up with new Go releases. .golangci.yml lists the linters explicitly and --new-from-rev only fails on new issues. * chore(ci): point make lint, CI and docs at golangci-lint@latest Completes the previous commit, which removed tools/ but left make lint, the CI cache paths, the /tools Dependabot entry and the docs pointing at it. --------- Co-authored-by: Thiago Souza <122435+tsouza@users.noreply.github.com> Co-authored-by: rita7lopes <ritamlopes@live.com.pt>
Closes #918
Summary
Lands the M1 tooling floor: golangci-lint,
-raceon the unit-test lane, theMakefile as the single entry point for build/test/lint/fuzz, go-arch-lint in
report-only mode — plus the one bug fix that's a hard prerequisite for anything
that pins transpiler behavior later.
the config's comments for why errcheck/structtag/composites are excluded),
-raceon the CI unit-test lane,Makefiletargets (build/test-unit/lint/arch-lint/fuzz) as the single entry point for these lanes,go-arch-lint wired in report-only mode.
TranspileExpressionV2's pushdown-substitute naming usedrand.Int63(), so the same query could emit different (but equivalent) SQLacross runs. Replaced with a per-transpile counter on
promql_parser.Expr,now covered by a direct determinism test (transpile the same expression twice
via the real engine path, assert byte-identical output).
tests pinning that a representative valid query parses to the expected
root/field shapes the planners consume, and that a representative invalid
query fails with the documented error class — cheap insurance against
upstream parser-dependency bumps changing shapes underneath the transpilers.
Lives in its own
reader/internal/parserpinpackage.FuzzParsetarget per query head,wired as
make fuzz HEAD=<head> [DURATION=<duration>]. Local andmanual-dispatch only — never a CI gate.
What's not in this PR
The original scope included a golden-SQL corpus (153 fixtures pinning the
literal ClickHouse SQL text each PromQL/LogQL/TraceQL query lowers to). That's
been dropped: a static SQL-text contract bakes in today's emitted shape,
including shapes that may themselves be bugs, so every fix becomes two edits
(code + golden) instead of one. Query-behavior pinning now lands at two other
layers instead — decision pins for internal routing/pushdown choices, and
response-level goldens for the Loki/Prometheus/Tempo JSON contracts Grafana
actually depends on. Neither is part of this PR; both land in later milestones
of the testing epic (#917, resequenced accordingly — see the epic for the
updated milestone order).
Test plan
go build ./...go test ./... -race -count=1(whole module, clean)make lint→ 0 issuesmake arch-lint→ no warningsmake fuzz HEAD=promql DURATION=2s(and logql/traceql) → no crashesTestTranspileIsDeterministic) run with-race -count=2, greensource project name and any AI-generated attribution text — none found